#include"httplib.h"
#include <iostream>

void Hello(const httplib::Request &req,httplib::Response &rsp)
{
    rsp.set_content("hello world!","text/plain");
    rsp.status=200;
}

void Numbers(const httplib::Request &req,httplib::Response &rsp)
{
    auto num=req.matches[1];
    rsp.set_content(num,"text/plain");
    rsp.status=200;
}

void Multipart(const httplib::Request &req,httplib::Response &rsp)
{
    auto ret=req.has_file("file");
    if(ret==false)
    {
        std::cout<<"not file upload\n";
        rsp.status=404;
        return ;
    }
    const auto& file=req.get_file_value("file");
    rsp.body.clear();
    rsp.body=file.filename;//文件名称
    rsp.body+="\n";
    rsp.body+=file.content;//文件内容
    rsp.set_header("Content-Type","text/plain");
    rsp.status=200;
}

int main()
{
    httplib::Server server;
    server.Get("/hi",Hello); // 注册针对/hi请求的Get请求的处理函数
    server.Get(R"(/numbers/(\d+))", Numbers); // 修正了这里的分号
    server.Post("/multipart",Multipart);
    std::cout << "Server started on port 9090..." << std::endl;
    server.listen("0.0.0.0",9090);
    return 0;
}
